import Vue from 'vue'
import Vuex from 'vuex'
import ajax from "element-ui/packages/upload/src/ajax";
import axios from 'axios'

Vue.use(Vuex)

export default new Vuex.Store({
    namespaced:true,
    state: {
        invoiveName:'invoiceSt',
        number:'',          //会员号
        money:-1,           //会员余额
        seatsId:-1,         //餐桌号
        totalPrice:-1,      //消费金额
        detailList:[],      //菜单详情


    },
    mutations: {
        selectVip(state,obj){
            state.number=obj.number;
            state.money=obj.money;

        },
        invoTableSelectSt(state,obj){
            state.seatsId=obj.seatsId;
            state.totalPrice=obj.totalPrice;
            state.detailList=obj.detailList;
        }
    },
    actions: {
        selectVip({commit},obj){
            // console.log(obj);
           return axios({
                url:'/website/memberSettlementController/queryMember',
                method:'post',
                data:{
                    number:obj.number,
                },
           }).then(respData=>{
               // console.log(respData);
               if (respData.data.Status === 'success') {
                   commit('selectVip',respData);
               }
               return respData.data
           }).catch(err=>{
               console.log(err);
           })
        },
        invoTableSelectSt({commit},obj){
            // console.log(obj);
            return axios({
                url:'/website/memberSettlementController/queryOrder',
                method:'post',
                data:{
                    mainId:obj.mainId,
                    seatsId:obj.seatsId
                },
            }).then(respData=>{
                // console.log(respData);
                if (respData.data.Status === 'success') {
                    commit('invoTableSelectSt',respData);
                }
                return respData.data
            }).catch(err=>{
                console.log(err);
            })
        },
        invoBuyOrderSt({commit},obj){
            // console.log(obj);
            return axios({
                url:'/website/memberSettlementController/Settlement',
                method:'post',
                data:{
                    totalPrice:obj.totalPrice,
                    number:obj.number,
                    payType:1,
                    money:1,
                },
            }).then(respData=>{
                // console.log(respData);
                if (respData.data.Status === 'success') {
                    commit('invoTableSelectSt',respData);
                }
                return respData.data
            }).catch(err=>{
                console.log(err);
            })
        }
    },
    modules: {
    }
})
